home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / PRUS101.ZIP / FSWAP.INC < prev    next >
Text File  |  1994-09-15  |  16KB  |  440 lines

  1. ; (***************************************************************************
  2. ;
  3. ;           RELEASE 1.00 - as contained in the file
  4. ;               by Peter Holschbach, 2:2450/660.3, GERMANY
  5. ;
  6. ;              --------------------------------------------
  7. ;               organized for Fido's PASCAL related echoes
  8. ;              --------------------------------------------
  9. ;
  10. ;    09/01/1994 to --/--/---- by Peter Holschbach, 2:2450/660.3,  GERMANY
  11. ;
  12. ;
  13. ;          As far as third party copyrights are not violated this
  14. ;          source code is hereby placed to the public domain. Use
  15. ;          it whatever way you want, but use AT YOUR OWN RISK.
  16. ;
  17. ;          In case you should modify the source rather send your
  18. ;          modifications to the unit's current organizer (see above for
  19. ;          NM address) than to spread it on your own. This will help to
  20. ;          keep the unit updated and grant a certain standard to all
  21. ;          other users as well.
  22. ;
  23. ;          The unit is currently still under work. So it might greatly
  24. ;          benefit of your participation.
  25. ;
  26. ;          Those who contributed to the following piece of source,
  27. ;          listed in alphabethical order:
  28. ;       ================================================================
  29. ;          Peter Holschbach ...
  30. ;       ================================================================
  31. ;          YOUR NAME WILL APPEAR HERE IF YOU CONTRIBUTE USEFUL SOURCE.
  32. ;
  33. ;          Credits in your own programs are as welcome as unnecessary.
  34. ;
  35. ;***************************************************************************)
  36.  
  37. ;-----------------------------------------------------------------------------
  38. ;-----------------------------------------------------------------------------
  39.  
  40.  
  41. CheckDiskDriver PROC
  42.  
  43.                  CLC
  44.                  RET
  45. ENDP
  46.  
  47. ;-----------------------------------------------------------------------------
  48. ;-----------------------------------------------------------------------------
  49.  
  50. DiskAllocate PROC
  51.                 CLD
  52.                 LEA     SI,SwapFilePath         ; DS:SI = pointer at pathname
  53.                 LODSB
  54.                 MOV     AH,0
  55.                 MOV     CX,AX                   ; size of string
  56.                 MOV     DL,0                    ; use default drive
  57.                 MOV     AX,[SI]                 ; first two chars in AX
  58.                 CMP     AH,':'                  ; is a drive selected ?
  59.                 JNE     @@useDefaultDrive
  60.                 SUB     AL,'A'-1                ; get drive Number
  61.                 MOV     DL,AL                   ; DL = new drive for swapout
  62. @@useDefaultDrive:
  63.                 LEA     DI,TmpName
  64.                 PUSH    CS
  65.                 POP     ES                      ; ES:DI = pointer at temp string
  66.                 CMP     CX,0
  67.                 JE      @@emptyString
  68.                 REP_FastMovs                    ; copy String to localStr
  69.                 PUSH    DI
  70.                 DEC     DI                      ; point at last char in string
  71.                 CMP     BYTE PTR ES:[DI],'\'    ; ensure backslash
  72.                 POP     DI                      ; point behind the last char
  73.                 JE      @@isBackslash
  74.                 MOV     BYTE PTR ES:[DI],'\'
  75.                 INC     DI
  76. @@emptyString:
  77. @@isBackslash:
  78.                 MOV     BYTE PTR ES:[DI],0      ; terminate string
  79.  
  80.                 ; ------- lets test if there is enough space on the drive
  81.  
  82.                 MOV     AH,36h                  ; get free disk space
  83.                                                 ; drive is in DL
  84.                 INT     21h                     ; AX*BX*CX = free Bytes
  85.                 CMP     AX,0FFFFh
  86.                 JE      @@SizeError
  87.                 MUL     BX
  88.                 MUL     CX                      ; DX,AX = disk size
  89.                 MOV     BX,SaveSize.lo
  90.                 MOV     CX,SaveSize.hi          ; CX,BX = space needed
  91.                 SUB     AX,BX
  92.                 SBB     DX,CX
  93.                 JC      @@isToSmall
  94.  
  95.                 PUSH    DS
  96.                 MOV     AX,CS
  97.                 MOV     DS,AX
  98.                 LEA     DX,TmpName              ; DS:DX = path
  99.                 MOV     AH,5Ah                  ; create temporary file
  100.                 MOV     CX,SwapFileAttr
  101.                 INT     21h
  102.                 POP     DS
  103.                 MOV     DX,AX                   ; handle to DX
  104.                 MOV     AH,ErrCreateTempFile    ; AL = code from DOS
  105.                                                 ; CY = Error
  106.                 RET
  107. @@SizeError:
  108.                 MOV     AX,ErrCantGetSize
  109.                 JMP     @@leave
  110. @@isToSmall:
  111.                 MOV     AX,ErrNotEnoughSpace
  112.  
  113. @@leave:
  114.                 STC
  115.                 RET
  116.  
  117. ENDP
  118. ;-----------------------------------------------------------------------------
  119. ;-----------------------------------------------------------------------------
  120.  
  121. SwapDisk PROC
  122.                 PUSH    DS
  123.                 ; ---------------- set write pointer to beginning of file
  124.                 MOV     AX,4200h        ; move file pointer, from start of file
  125.                 MOV     BX,Handle       ; Handle number
  126.                 MOV     CX,0
  127.                 MOV     DX,0            ; Offset = 0
  128.                 INT     21h
  129.  
  130.                 ; --------------- prepare writing
  131.  
  132.                 LES     DI,SaveSize     ; ES,DI = Size to save
  133.  
  134.                 MOV     DX,OFFSET SavePoint
  135.                 MOV     AX,SEG SavePoint
  136.                 MOV     DS,AX           ; DS,DX = pointer at start
  137.  
  138.                 ; --------------- write to disk
  139. @@saveLoop:
  140.                 MOV     BX,Handle       ; Handle number
  141.                 MOV     CX,DosBlockSize ; save max. blocksize
  142.                 MOV     AX,ES
  143.                 CMP     AX,0            ; less then 64k to save ?
  144.                 JNE     @@savemax       ; no -> full size
  145.                 CMP     DI,DosBlockSize
  146.                 JNB     @@savemax       ; if there is more then one block
  147.                 MOV     CX,DI           ; save the rest
  148. @@savemax:
  149.                 MOV     AH,40h          ; write to a file
  150.                 PUSH    DX
  151.                 PUSH    ES
  152.                 PUSH    DI
  153.                 INT     21h
  154.                 POP     DI
  155.                 POP     ES
  156.                 POP     DX
  157.                 JC      @@saveErr         ; error during writing ?
  158.                 CMP     AX,CX           ; check if all bytes written
  159.                 JNE     @@saveErr         ; error during writing ?
  160.                 SUB     DI,AX           ; size to save = size to save - saved
  161.                 MOV     AX,ES
  162.                 SBB     AX,0
  163.                 MOV     ES,AX           ; ES,DI = ES,DI - CX = size to save
  164.  
  165.                 ADD     AX,DI           ; ES+DI = 0 -> nothing left to write
  166.                 CMP     AX,0
  167.                 JE      @@ready
  168.  
  169.                 MOV     AX,DS
  170.                 ADD     AX,DosBlockSize/16 ; next Segment to save
  171.                 MOV     DS,AX
  172.                 JMP     @@saveLoop
  173. @@ready:
  174.                 ; ----------  commite data
  175.                 MOV     BX,Handle
  176.                 MOV     AH,45h          ; duplicate Handle
  177.                 INT     21h
  178.                 JC      @@cantDup
  179.                 MOV     BX,AX           ; new Handle number
  180.                 MOV     AH,03Eh         ; close Handle
  181.                 INT     21h
  182. @@cantDup:
  183.                 POP     DS
  184.                 CLC
  185.                 RET
  186.  
  187. @@saveErr:
  188.                 POP     DS
  189.                 MOV     AH,ErrWriteFile
  190.                 STC
  191.                 RET
  192.  
  193. ENDP
  194.  
  195.  
  196. ;-----------------------------------------------------------------------------
  197. ;-----------------------------------------------------------------------------
  198.  
  199. DiskDeAllocate PROC
  200.  
  201.                 PUSH    DS
  202.                 LEA     DX,TmpName
  203.                 PUSH    CS
  204.                 POP     DS
  205.                 MOV     AH,41h                  ; delete directory entry
  206.                 INT     21h
  207.                 POP     DS
  208.                 CLC
  209.                 RET
  210. ENDP
  211. ;-----------------------------------------------------------------------------
  212. ;-----------------------------------------------------------------------------
  213.  
  214. CheckEMSDriver  PROC
  215.                 PUSH     DS
  216.                 MOV      AX,3567h         ; get interrupt vector 67h
  217.                 INT      21h              ; ES:BX = Vector
  218.                 MOV      AX,SEG @CODE
  219.                 MOV      DS,AX
  220.                 LEA      SI,EMSDeviceName ; DS:SI = pointer at name
  221.                 MOV      DI,0Ah           ; offset device name
  222.                 CLD
  223. IF ((SIZE EMSDeviceName) MOD 2) NE 0
  224.                 MOV      CX,SIZE EMSDeviceName ; compare counter
  225.                 REPE     CMPSB            ; compare Strings until not equal
  226. ELSE
  227.                 MOV      CX,(SIZE EMSDeviceName) / 2 ; compare counter
  228.                 REPE     CMPSW            ; compare Strings until not equal
  229. ENDIF
  230.                 POP      DS
  231.                 CLC
  232.                 JE       @@EmsOk
  233. @@EMSerror:
  234.                 STC
  235.                 RET
  236. @@EmsOK:
  237.                 ; check if LIM EMS >= 4.0
  238.                 MOV      AH,46h
  239.                 INT      67h
  240.                 OR       AH,AH
  241.                 JNE      @@EMSerror
  242.                 CMP      AL,40h         ; version 4.0 ?
  243.                 JL       @@EMSerror     ; the version is to old
  244.                 CLC
  245.                 RET
  246. ENDP
  247.  
  248. ;-----------------------------------------------------------------------------
  249. ;-----------------------------------------------------------------------------
  250.  
  251. EMSAllocate PROC
  252.                 MOV     AX,SaveSize.lo
  253.                 MOV     DX,SaveSize.hi          ; DX,AX = size in bytes
  254.                 MOV      BX,EmsPageSize         ; Size of one page
  255.                 DIV      BX                     ; AX = DX,AX DIV BX
  256.                 CMP      DX,0
  257.                 JE       @@Hit16K
  258.                 INC      AX
  259. @@Hit16k:
  260.                 MOV     BX,AX
  261.                 MOV     AH,43h                  ; allocate EMS
  262.                 INT     67h
  263.                 CMP     AH,0
  264.                 CLC
  265.                 JE      @@EmsOk
  266.                 STC
  267. @@EmsOK:
  268.                 RET
  269. ENDP
  270.  
  271. ;-----------------------------------------------------------------------------
  272. ;-----------------------------------------------------------------------------
  273.  
  274. SwapEMS PROC
  275.                 PUSH    DS              ; save Turbo's DS
  276.                 PUSH    CS
  277.                 POP     DS
  278.                 PUSH    CS
  279.                 POP     ES              ; DS = ES = CS
  280.  
  281.                 LEA     SI,SaveSize
  282.                 LEA     DI,EMSmovStruc.RegionLength
  283.                 MOVSW
  284.                 MOVSW                   ; copy the length
  285.                 XOR     AX,AX
  286.                 STOSB                   ; source memory type = conventional
  287.                 STOSW                   ; handle = 0
  288.                 MOV     AX,OFFSET SavePoint
  289.                 STOSW
  290.                 MOV     AX,SEG SavePoint
  291.                 STOSW                   ; start from "SavePoint"
  292.  
  293.                 MOV     AL,1
  294.                 STOSB                   ; copy to EMS
  295.                 MOV     AX,Handle
  296.                 STOSW
  297.                 XOR     AX,AX
  298.                 STOSW
  299.                 STOSW
  300.  
  301.                 LEA     SI,EMSmovStruc.RegionLength
  302.                 MOV     AX,5700h
  303.                 INT     67h
  304.                 POP     DS
  305.                 OR      AH,AH
  306.                 JNZ     @@EMSerror
  307.                 RET
  308. @@EMSerror:
  309.                 MOV     AL,AH
  310.                 MOV     AH,ErrManager
  311.                 STC
  312.                 RET
  313. ENDP
  314.  
  315.  
  316. ;-----------------------------------------------------------------------------
  317. ;-----------------------------------------------------------------------------
  318.  
  319.  
  320. EMSDeAllocate PROC
  321.                 PUSH    DS
  322.                 MOV     DX,Handle
  323.                 MOV     AH,45h
  324.                 INT     67h
  325.                 POP     DS
  326.                 CMP     AH,00
  327.                 JNE     @@EmsError
  328.                 RET
  329. @@EmsError:
  330.                 MOV     AL,AH
  331.                 MOV     AH,ErrManager   ; to show "a message from EMS"
  332.                 STC
  333.                 RET
  334. ENDP
  335.  
  336. ;-----------------------------------------------------------------------------
  337. ;-----------------------------------------------------------------------------CheckXMSDriver
  338.  
  339. CheckXMSDriver  PROC
  340.  
  341.          MOV    AX,4300h        ; installation check
  342.          INT    2Fh
  343.          CMP    AL,80h
  344.          JE     @@XmsOK
  345.          STC
  346.          RET
  347. @@XmsOk:
  348.          MOV    AX,4310h        ; get adress
  349.          INT    2Fh
  350.          MOV    XMSPointer.Ofst,BX
  351.          MOV    XMSPointer.Segm,ES
  352.          CLC
  353.          RET
  354. ENDP
  355.  
  356. ;-----------------------------------------------------------------------------
  357. ;-----------------------------------------------------------------------------
  358.  
  359. XMSAllocate PROC
  360.  
  361.                 MOV     AX,SaveSize.lo
  362.                 MOV     DX,SaveSize.hi  ; DX,AX = size in bytes
  363.                 MOV     BX,1024
  364.                 DIV     BX              ; calculate size in kbyte
  365.                 CMP     DX,0
  366.                 JE      @@hit1024
  367.                 INC     AX              ; never round down
  368. @@hit1024:
  369.                 MOV     DX,AX           ; size needed in AX
  370.                 MOV     AH,09h          ; allocate EMM block
  371.                 CALL    XmsPointer      ; XMS Call
  372.                 CMP     AX,1            ; 1 = ok
  373.                 JE      @@XmsOK         ; no problems ?
  374.                 MOV     AH,ErrManager   ; to show "a message from XMS"
  375.                 MOV     AL,BL           ; erroer number from XMS manager
  376.                 STC
  377.                 RET
  378. @@XmsOk:
  379.                 CLC     ; everything is ok
  380.                 RET
  381. ENDP
  382.  
  383. ;-----------------------------------------------------------------------------
  384. ;-----------------------------------------------------------------------------
  385.  
  386. SwapXMS PROC
  387.                 PUSH    DS              ; save DS from Turbo Pascal
  388.                 MOV     AX,CS
  389.                 MOV     DS,AX           ; DS = CS
  390.                 MOV     ES,AX           ; ES = CS
  391.                 CLD
  392.                 LEA     DI,XMSStructur  ; CS:DI = Pointer ad XMS structure
  393.                 LEA     SI,SaveSize     ; CS:SI = memory we use
  394.                 MOVSW                   ; save size
  395.                 MOVSW                   ;    in structure
  396.                 XOR     AX,AX           ; clear AX
  397.                 STOSW                   ; source handle = 0 => DOS RAM
  398.                 MOV     AX,OFFSET SavePoint
  399.                 STOSW
  400.                 MOV     AX,SEG SavePoint
  401.                 STOSW                   ; start adress
  402.                 MOV     AX,Handle       ; handle destination
  403.                 STOSW
  404.                 XOR     AX,AX
  405.                 STOSW
  406.                 STOSW                   ; offset destination = 0
  407.                 MOV     AH,0Bh          ; XMS : "copy block"
  408.                 LEA     SI,XMSStructur  ; DS:SI = pointer at structure
  409.                 CALL    XmsPointer      ; XMS Call
  410.                 POP     DS
  411.                 CMP     AX,1            ; CY = 0 if equal
  412.                 JNE     @@XMSerror
  413.                 RET
  414. @@XMSerror:
  415.                 MOV     AH,ErrManager   ; to show "a message from XMS"
  416.                 MOV     AL,BL           ; erroer number from XMS manager
  417.                 STC
  418.                 RET
  419.  
  420. ENDP
  421.  
  422.  
  423. ;-----------------------------------------------------------------------------
  424. ;-----------------------------------------------------------------------------
  425.  
  426. XMSDeAllocate PROC
  427.  
  428.                 MOV     DX,Handle
  429.                 MOV     AH,0Ah
  430.                 CALL    XmsPointer      ; XMS Call
  431.                 CMP     AX,1            ; CY = 0 if equal
  432.                 JNE     @@XMSerror
  433.                 RET
  434. @@XMSerror:
  435.                 MOV     AH,ErrManager   ; to show "a message from XMS"
  436.                 MOV     AL,BL           ; erroer number from XMS manager
  437.                 STC
  438.                 RET
  439.  
  440. ENDP